import time
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

d = webdriver.Edge()   #获取浏览器
d.get("https://ebank.xacbank.com/XAEIBankDemo/page/login/login.html?t=1679974008665http://127.0.0.1/ranzhi/www/")   #打开网页
# time.sleep(1)
#西安银行，密码123456，登录
d.find_element(By.ID,"account").send_keys("123456")
d.find_element(By.ID,"login").click()
time.sleep(2)
#西安银行->转行汇款->行内批量转账
d.find_element(By.ID,"fw-gen-10009-closable").click()
time.sleep(2)
d.find_element(By.ID,"1").click()
time.sleep(2)
d.find_element(By.XPATH,"/html/body/div[4]/div/ul[4]/li[2]").click()
time.sleep(2)
# 设置某个付款账户，不使用默认值
iframe = d.find_element("id","fw-gen-10007-body")
d.switch_to.frame(iframe)
role = d.find_element("id","payAccount")
s = Select(role)
ls = s.options
listtext = []
for i in ls:
    listtext.append(i.text)
print(listtext)
s.select_by_visible_text(listtext[2])
time.sleep(2)
# 选择收款人，从里面选择赵云、马超
d.find_element(By.ID, "icon_find1").click()
time.sleep(2)
d.switch_to.default_content()
iframe1=d.find_element(By.ID,"fw-gen-10011-iframe")
d.switch_to.frame(iframe1)
time.sleep(2)
d.find_element(By.XPATH,"/html/body/div/div[3]/div/table/tbody/tr[2]/td[1]/label").click()
d.find_element(By.XPATH,"/html/body/div/div[3]/div/table/tbody/tr[3]/td[1]/label").click()
time.sleep(2)
d.switch_to.parent_frame()
d.find_element(By.CLASS_NAME,"btn.btn-primary").click()
time.sleep(2)
# 设置收款人的转账金额分别为1000、2000
iframe = d.find_element("id","fw-gen-10007-body")
d.switch_to.frame(iframe)
d.find_element(By.XPATH,"/html/body/div/table[2]/tbody/tr[1]/td[4]/input").send_keys("1000")
d.find_element(By.XPATH,"/html/body/div/table[2]/tbody/tr[2]/td[4]/input").send_keys("2000")
# 点击下一步
d.find_element(By.ID,"next_btn").click()
time.sleep(2)
# 点击提交
d.find_element(By.XPATH,"/html/body/div/div[3]/form/div[2]/table/tbody/tr[2]/td/input").send_keys("转账")
d.find_element(By.ID,"submit_btn").click()
time.sleep(2)
#截图
timestr = time.strftime("%Y-%m-%d_%H-%M-%S",time.localtime())
d.get_screenshot_as_file(f"d:\\xianyinghang{timestr}.png")
time.sleep(3)
d.quit()
